﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SelectUser.aspx.cs" Inherits="Portal.SelectUser" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <base target="_self"></base>
    <title>选择用户</title>
    <script src="js/jquery.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            $("input[id$=RadioButton1]").attr("name","username");
        });
    </script>
</head>
<body style="overflow-x: hidden; overflow-y: hidden;">
    <form id="form1" runat="server">
    <div>
    <div class="pt10 pb10 pr10">
    &nbsp;&nbsp;&nbsp;&nbsp;
        <asp:TextBox ID="txtSearch" runat="server" Width="500"></asp:TextBox>&nbsp;&nbsp;&nbsp;&nbsp;<asp:Button ID="btnSearch"
            runat="server" Text="查询" CssClass="btn btn-primary" 
            onclick="btnSearch_Click" /></div>
        <div style="float: left; width: 240px; margin-left: 5px; height: 450px; overflow: scroll;">
            <asp:TreeView ID="UserTreeView" runat="server" OnSelectedNodeChanged="UserTreeView_SelectedNodeChanged">
                <NodeStyle BorderStyle="None" />
                
                <SelectedNodeStyle Font-Bold="True" />
            </asp:TreeView>
        </div>
        <div style="float: left; width: 545px; height: 450px;">
            <div style="overflow-x: hidden; overflow-y: scroll; height: 230px;">
                <table class=" table table-hover table-bordered table-condensed listTable" style="width: 545px; overflow: hidden;">
                    <thead>
                        <tr class="bg">
                            <th width="50px">
                                选择
                            </th>
                            <th width="150px">
                                用户名
                            </th>
                            <th width="150px">
                                岗位
                            </th>
                            <th width="200px">
                                Email
                            </th>
                        </tr>
                    </thead>
                    <tbody id="tbody">
                        <asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound">
                            <ItemTemplate>
                                <tr id='<%# Container.ItemIndex+1 %>' class="TableDataRow">
                                    <td width="29px">
                                        <asp:CheckBox ID="CheckBox1" runat="server" />
                                        <asp:RadioButton ID="RadioButton1" runat="server" GroupName="username" />
                                    </td>
                                    <td width="148px">
                                        <asp:Label ID="Label1" runat="server" Text='<%# Eval("FirstName") %>'></asp:Label>
                                    </td>
                                    <td width="156px">
                                        <asp:Label ID="Label2" runat="server" Text='<%# Eval("Title") %>'></asp:Label>
                                    </td>
                                    <td width="212px">
                                        <asp:Label ID="Label3" runat="server" Text='<%# Eval("email") %>'></asp:Label>
                                    </td>
                                    <td style="display: none;">
                                        <asp:HiddenField ID="UserAccount" runat="server" Value='<%# Eval("ShortName") %>' />
                                    </td>
                                    <td style="display: none;">
                                        <asp:HiddenField ID="UserID" runat="server" Value='<%# Eval("EmployeeID") %>' />
                                    </td>
                                </tr>
                            </ItemTemplate>
                        </asp:Repeater>
                    </tbody>
                </table>
            </div>
            <div style="overflow: hidden; height: 30px; width: 545px;">
                <table class="listTable" style="width: 545px; overflow: hidden;">
                    <tr>
                        <td>
                            <asp:Button ID="Button1" Text="选择" runat="server" CssClass="btn btn-warning" OnClientClick="return CheckSelectItem()"
                                OnClick="Button1_Click" Height="25" />
                            <script type="text/javascript" language="javascript">
                                function CheckSelectItem() {
                                    var isok = false;
                                    $("#tbody").find("tr").each(function () {
                                        if ($(this).find("td:eq(0)").children().attr("checked")) {
                                            isok = true;
                                        }
                                    });
                                    if (!isok) {
                                        //alert("");
                                        return false;
                                    } else {
                                        return true;
                                    }
                                }
                            </script>
                            <asp:Button ID="Button2" Text="取消" runat="server" CssClass="btn" OnClientClick="return Cancel()"
                                OnClick="Button2_Click" Height="25" />
                            <script type="text/javascript" language="javascript">
                                function Cancel() {
                                    var isok = false;
                                    $("#tab").find("tr").each(function () {
                                        if ($(this).find("td:eq(0)").children().attr("checked")) {
                                            isok = true;
                                        }
                                    });
                                    if (!isok) {
                                        //alert("");
                                    } else {
                                        if (confirm("您确定要取消吗？")) {
                                            return true;
                                        }
                                    }
                                    return false;
                                }
                            </script>
                            <input type="button" value="确定" class="btn  btn-primary" onclick="Confirm()"  style="height:25px;"/>
                            <script type="text/javascript" language="javascript">
                                function Confirm() {
                                    var returnJson = "";
                                    if ($("#selectTyep").val() == "1") { //单选
                                        $("#tbody tr").each(function () {
                                            if ($(this).find("td:eq(0)").children().attr("checked")) {
                                                returnJson = "{'FullName':'" + $.trim($(this).find("td:eq(1)").text()) + "',";
                                                returnJson += "'JobFunction':'" + $.trim($(this).find("td:eq(2)").text()) + "',";
                                                returnJson += "'Email':'" + $.trim($(this).find("td:eq(3)").text()) + "',";
                                                returnJson += "'Account':'" + $.trim($(this).find("td:eq(4)").children().val()) + "',";
                                                returnJson += "'UserID':'" + $.trim($(this).find("td:eq(5)").children().val()) + "'}";
                                            }
                                        });
                                    } else if ($("#selectTyep").val() == "2") { //多选
                                        returnJson += "[";
                                        //debugger;
                                        $("#tab tr").each(function () {
                                            returnJson += "{'FullName':'" + $.trim($(this).find("td:eq(1)").text()) + "',";
                                            returnJson += "'JobFunction':'" + $.trim($(this).find("td:eq(2)").text()) + "',";
                                            returnJson += "'Email':'" + $.trim($(this).find("td:eq(3)").text()) + "',";
                                            returnJson += "'Account':'" + $.trim($(this).find("td:eq(4)").children().val()) + "',";
                                            returnJson += "'UserID':'" + $.trim($(this).find("td:eq(5)").children().val()) + "'},";
                                        });
                                        returnJson = returnJson.substring(0, returnJson.lastIndexOf(","));
                                        returnJson += "]";
                                    }
                                    if (returnJson == "" || returnJson == "]") {
                                        alert('请选择相应的人员!');
                                        return;
                                    }
                                    window.returnValue = returnJson;
                                    window.close();
                                }
                            </script>
                            <input type="button" value="关闭" class="btn" onclick="CloseForm()" style="height:25px;" />
                            <script type="text/javascript" language="javascript">
                                function CloseForm() {
                                    window.close();
                                }
                            </script>
                        </td>
                    </tr>
                </table>
            </div>
            <div id="SelectedList" runat="server" visible="false" style="overflow: hidden; height: 190px;">
                <div style="height: 190px; overflow-x: hidden; overflow-y: scroll;">
                    <table class="table table-hover table-bordered table-condensed listTable" style="width: 545px; overflow: hidden;">
                        <thead>
                            <tr class="bg">
                                <th width="50px">
                                    选择
                                </th>
                                <th width="150px">
                                    用户名
                                </th>
                                <th width="150px">
                                    岗位
                                </th>
                                <th width="200px">
                                    Email
                                </th>
                            </tr>
                        </thead>
                        <tbody id="tab">
                            <asp:Repeater ID="Repeater2" runat="server">
                                <ItemTemplate>
                                    <tr id='<%# Container.ItemIndex+1 %>' class="TableDataRow">
                                        <td>
                                            <asp:CheckBox ID="CheckBox2" runat="server" />
                                        </td>
                                        <td>
                                            <%# Eval("FirstName")%>
                                        </td>
                                        <td>
                                            <%# Eval("Title")%>
                                        </td>
                                        <td>
                                            <%# Eval("email") %>
                                        </td>
                                        <td style="display: none;">
                                            <asp:HiddenField ID="UserAccount" runat="server" Value='<%# Eval("ShortName") %>' />
                                        </td>
                                        <td style="display: none;">
                                            <asp:HiddenField ID="UserID" runat="server" Value='<%# Eval("EmployeeID") %>' />
                                        </td>
                                    </tr>
                                </ItemTemplate>
                            </asp:Repeater>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
    <asp:HiddenField ID="selectTyep" runat="server" />
    </form>
</body>
</html>
